<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/mobileHead.jsp" %>
	<div class="content">
		<div class="title"><b><font color="#0487e4"><c:out value="${menu.menuName}"/></font></b></div>
		<table border="0" cellspacing="0" cellpadding="0" width="100%" style="text-align:center;color:#999999;">
			<tr>
				<td height="2" bgcolor="#199fff" colspan="3"></td>
			</tr>
			<tr>
				<td width="40" height="29" style="color:#4a7ed5;">번호</td>
				<td width="220" style="color:#4a7ed5;">제목</td>
				<td width="60" style="color:#4a7ed5;">날짜</td>
				<td width="1">&nbsp;</td>
			</tr>
			<tr>
				<td height="1" bgcolor="#199fff" colspan="3"></td>
			</tr>
		</table>
		<table border="0" cellspacing="0" cellpadding="0" width="100%" style="text-align:center;color:#999999;" id="boardList">
		</table>
		<table border="0" cellspacing="0" cellpadding="0" width="100%" style="text-align:center;color:#999999;">
			<!-- <tr>
				<td height="34">4</td>
				<td align="left"><a href="#"><font color="#666666">안녕하세요.알고 있어야 당하지 않는다.</font></a></td>
				<td>14-10-01</td>
			</tr>
			<tr>
				<td height="1" bgcolor="#dddddd" colspan="3"></td>
			</tr>
			<tr>
				<td height="34">3</td>
				<td align="left"><a href="#"><font color="#666666">안녕하세요.알고 있어야 당하지 않는다.</font></a></td>
				<td>14-10-01</td>
			</tr>
			<tr>
				<td height="1" bgcolor="#dddddd" colspan="3"></td>
			</tr>
			<tr>
				<td height="34">2</td>
				<td align="left"><a href="#"><font color="#666666">안녕하세요.알고 있어야 당하지 않는다.</font></a></td>
				<td>14-10-01</td>
			</tr>
			<tr>
				<td height="1" bgcolor="#dddddd" colspan="3"></td>
			</tr>
			<tr>
				<td height="34">1</td>
				<td align="left"><a href="#"><font color="#666666">안녕하세요.알고 있어야 당하지 않는다.</font></a></td>
				<td>14-10-01</td>
			</tr>
			<tr>
				<td height="1" bgcolor="#dddddd" colspan="3"></td>
			</tr> -->
			<tr>
				<td height="10"></td>
			</tr>
			<tr>
				<td align="center" colspan="3">
				<table border="0" cellspacing="0" cellpadding="0" style="color:#4a7ed5;">
					<tr>
						<td id="firstLeft"></td>
						<td width="7"></td>
						<td id="left"></td>
						<td width="7"></td>
						<td id="cur"></td>
						<td width="7"></td>
						<td id="right"></td>
						<td width="7"></td>
						<td id="endRight"></td>
					</tr>
				</table>
				</td>
			</tr>
		</table>
	</div>
<form  id="frm" name="frm" method="post" style="display:none;">
	<input type="text" name="menuIndex" id="menuIndex" value="${menu.menuIndex}">
	<input type="text" name="textID" id="paramTextID">
</form>
<script type="text/javascript">
  var _this = this;
  var markerSetting = {
  		paging:{}
  }
  init();
  function init() {
  		markerSetting.paging.page = '<c:out value="${totalPage.page}"/>';
		markerSetting.paging.totalPage ='<c:out value="${totalPage.totalPage}"/>';
		markerSetting.paging.nowSeq = 1;
		markerSetting.paging.menuIndex = $("#menuIndex").val();
		getBoardList();
  }
  
  function getBoardList() {
	  	var url='/m/getBoardList.json';
  	
		var param=markerSetting.paging;
		var list="";
		var className = "";
		
		AjaxPost(url, param, function(data){
//	 		jsonLog(data.boardList);
			$.each(data.boardList,function(index, value){
				list += "<tr onClick='goView("+value.boardType+","+value.textID+")'>";
				list += "	<td width='40' height='34'>"+value.textNum+"</td>";
				list += "	<td width='220' align='left'><font color='#666666'>"+value.title+"</font></td>";				
				list += "	<td width='60' id='regiTime'>"+formatter.dateFormatYYYYMMDD2(new Date(value.regiTime))+"</td>";				
				list += "	<td width='1' style='diplay:none'><input type='hidden' value="+value.textID+" id='textID'></td>";
				list += "</tr>";
				list += "<tr>";
				list += "	<td height='1' bgcolor='#cbcbcb' colspan='5'></td>";
				list += "</tr>";				
			});
			$("#boardList").html(list);
			
			markerSetting.paging.totalPage= data.totalPage.totalPage;
			makePaging();
		});
  }
  
  function getSearchBoardList() {
	  markerSetting.paging.searchType = $("select[name=searchType]").val();
	  markerSetting.paging.searchName = $("#searchName").val();
	  
	  getBoardList();
  }
  function makePaging() {
  	$('#pagenation').html("");
		var totalPage = markerSetting.paging.totalPage;
		var nowPage = markerSetting.paging.page;
		var html='';
		var firstLeft="", left="", cur = "", right="", endRight="";
		var setFunctionName='';
		var index=(nowPage-10);
		var indexCount=0;
		
		var endPage = totalPage / 10;
		if (totalPage % 10 > 0) {
			endPage = endPage + 1;
		}
		
		if(index>1){
			firstLeft+='<a onclick="changePaging(1,\'before\''+')" onFocus=this.blur()><img src="${imgUrl }/m/btn1.jpg"/ boarder=0></a>';
			left+='<a onclick="changePaging('+index+',\'before\''+')" onFocus=this.blur()><img src="${imgUrl }/m/btn2.jpg"/  border=0></a>';
		}
//		//logs('totalPage/20 = '+totalPage/20);
		for(;index<=endPage;index++){
			if((index)==nowPage){
				setFunctionName='';
			}else{
				setFunctionName=' onclick="changePaging('+index+')"';
			}
			
			if(index>0){
					
				if(index == nowPage) {
					cur+='<a hrer="#" '+setFunctionName+'><b>'+index+'</b></a>';
				} else {
					cur+='<a href="#" '+setFunctionName+'>'+index+'</a>';
				}
				
				indexCount++;
			}
			if(indexCount>9){
				right+='<a onclick="changePaging('+index+',\'after\''+')" onFocus=this.blur()><img src="${imgUrl }/m/btn3.jpg"/ border=0></a>';
				endRight+='<a onclick="changePaging('+totalPage+',\'after\''+')" onFocus=this.blur()><img src="${imgUrl }/m/btn4.jpg"/ border=0></a>';
				break;
			}
			
		}
		$("#firstLeft").html(firstLeft);
		$("#left").html(left);
		$("#cur").html(cur);
		$("#right").html(right);
		$("#endRight").html(endRight);
  }
  
  function changePaging(index, option){
		logs('markerSetting.paging.totalPage = '+markerSetting.paging.totalPage);
		if(option==null){
			logs(', index = '+index);
			
			markerSetting.paging.page=index;
			markerSetting.paging.start=0;
			markerSetting.paging.end=0;
			getBoardList();
		}else{
			if(option=='before'){
				var next = index-9;
				while(next<=0){
					next++;
				}
				logs('next = '+next+', index = '+index);
				markerSetting.paging.page=next;
				markerSetting.paging.start=0;
				markerSetting.paging.end=0;
				getBoardList();
			}else if(option=='after'){
				var next = index+9;
				while(next>=(markerSetting.paging.totalPage/10)+1){
					next--;
				}
				logs('next = '+next+', index = '+index);
				markerSetting.paging.page=next;
				markerSetting.paging.start=0;
				markerSetting.paging.end=0;
				getBoardList();
			}
		}
	}
	
	function goBoardListMain(type) {			
			$("#menuIndex").val(type);
			var url = "/m/boardListMain";	
			$("#frm").attr("action", url);
			$("#frm").submit();
			
			return false;
	 }
	function goView(menuIndex, textID) {
		if(menuIndex > 4) {
		  //로그인 체크
			<% if(session.getAttribute(UserModel.USER_SESSION_INFO) == null) {%>
				$("#paramTextID").val(textID);
				$("#frm").attr("action", "/m/userBoardView");
			  	$("#frm").submit();
			  	return;
			<% }%>
			
			var myPoint = 0, boardPoint = 0;
			var isUseCheck = "N";
			
			var url='/board/getMyInfo.json';
			var param = "textID="+textID+"&menuIndex="+$("#menuIndex").val();
			
			AjaxPost(url, param, function(data){
				myPoint = data.userData.point; //내 금액
				boardPoint = data.boardData.usePoint; //게시글의 구매금액
				isUseCheck = data.usePointCheck; //구매체크
				
				<% if(!"40".equals(session.getAttribute(UserModel.USER_LEVEL))){ %>
				if(myPoint < boardPoint) {
					alert('포인트가 부족합니다.');
					return;			
				}
				
				if(isUseCheck != 'Y') {
					if(!confirm('구매 하시겠습니까?')) {
						return;
					}
				}
				<% } %>
				$("#paramTextID").val(textID);
				$("#frm").attr("action", "/m/boardView");
			  	$("#frm").submit();
			});
		} else {
			$("#paramTextID").val(textID);
			$("#frm").attr("action", "/m/boardView");
		  	$("#frm").submit();
		}	
	} 
		  	
	 function hitEnterKey(e){
		  if(e.keyCode == 13){
			  getSearchBoardList();			  
			  return false;
		  }
	   } 
</script>
<%@ include file="/WEB-INF/views/include/mobileBottom.jsp" %>